define([ "app", "jquery", "md5", "ecb", "services/UserService",
		"resources/UserResource", "resources/AddCompanyResource" ],
		function(app) {

			var deps = [ "$scope", "$state", "$window","type","$modalInstance", "$location", "$stateParams", "UserService", "UserResource", "AddCompanyResource" ];

			function controller($scope, $state, $window,type, $modalInstance, $location, $stateParams, UserService, UserResource, AddCompanyResource) {

				$scope.type = type;
				initDate($scope,AddCompanyResource);
				
				$scope.setCompanyName =function(){
					var companyName =$("#companyCodeId").text();
					$scope.companyVo.companyName=companyName;
				};
				$scope.updateCompany = function() {

					if ($scope.companyEditForm.$invalid) {
						return false;
					}
					$scope.companyEditForm.$invalid = true;
					AddCompanyResource.update($scope.companyVo).success(function(data){
						$scope.companyEditForm.$invalid = false;
						if (data.id) {
							$modalInstance.close($scope.companyVo);
						}
		            });
					
				};

				$scope.close = function($scope,AddCompanyResource) {
					$modalInstance.close();
				};
			}
			
			/**
			 * 初始化下拉列表
			 */
			function initDate($scope, AddCompanyResource){
				
				AddCompanyResource.queryOrgList(0).success(function(data){
					$scope.orgList=data;
	            });
				
				// 初始化公司数据
				AddCompanyResource.queryCompanyVoById($scope.type).success(function(data){
					$scope.companyVo=data;
	            });
				
				
			}
			controller.$inject = deps;
			return app.lazy.controller("EditCompanyController", controller);
		});
